#!/bin/sh

# Installation directory
base_dir=`realpath "$0"/../../../../`
#echo base_dir=$base_dir

# Input file
in=$base_dir/extra/stats/rrd/proxy-5min.rrd
# Output file with proxy request processings stats
out_proxy_reqs=$base_dir/extra/stats/png/proxy-reqs.png
# Output file with proxy transactions stats
out_proxy_tr=$base_dir/extra/stats/png/proxy-tr.png
# Output file with proxy Java VM stats
out_vm=$base_dir/extra/stats/png/proxy-vm.png

rrdtool graph $out_proxy_reqs	                        \
	 --title "Proxy request processing stats"	\
	 --vertical-label "per second"	        	\
	 --alt-autoscale-max				\
	 --lower-limit 0				\
	 --base 1000					\
	 --slope-mode					\
							\
	 DEF:ds0=$in:nReqProc:AVERAGE			\
	 DEF:ds1=$in:nResProc:AVERAGE			\
	 DEF:ds10=$in:nReqNProc:AVERAGE			\
	 DEF:ds11=$in:nResNProc:AVERAGE			\
							\
	 VDEF:ds0max=ds0,MAXIMUM			\
	 VDEF:ds0avg=ds0,AVERAGE			\
	 VDEF:ds0cur=ds0,LAST				\
   	 AREA:ds0#00FF00:"Req processed\:    ":    	\
	 GPRINT:ds0cur:"Cur\: %5.0lf\t"			\
	 GPRINT:ds0avg:"Avg\: %5.0lf\t"			\
	 GPRINT:ds0max:"Max\: %5.0lf\l"	 		\
							\
         VDEF:ds10max=ds10,MAXIMUM			\
	 VDEF:ds10avg=ds10,AVERAGE			\
	 VDEF:ds10cur=ds10,LAST				\
   	 AREA:ds10#FF0000:"Req not processed\:":STACK   \
	 GPRINT:ds10cur:"Cur\: %5.0lf\t"		\
	 GPRINT:ds10avg:"Avg\: %5.0lf\t"		\
	 GPRINT:ds10max:"Max\: %5.0lf\l"	 	\
							\
	 CDEF:_ds1=ds1,-1,*				\
         VDEF:ds1max=ds1,MAXIMUM			\
	 VDEF:ds1avg=ds1,AVERAGE			\
	 VDEF:ds1cur=ds1,LAST				\
   	 AREA:_ds1#00BF47:"Res processed\:    "		\
	 GPRINT:ds1cur:"Cur\: %5.0lf\t"			\
	 GPRINT:ds1avg:"Avg\: %5.0lf\t"			\
	 GPRINT:ds1max:"Max\: %5.0lf\l"	 		\
							\
	 CDEF:_ds11=ds11,-1,*				\
         VDEF:ds11max=ds11,MAXIMUM			\
	 VDEF:ds11avg=ds11,AVERAGE			\
	 VDEF:ds11cur=ds11,LAST				\
   	 AREA:_ds11#FF0000:"Res not processed\:":STACK  \
	 GPRINT:ds11cur:"Cur\: %5.0lf\t"		\
	 GPRINT:ds11avg:"Avg\: %5.0lf\t"		\
	 GPRINT:ds11max:"Max\: %5.0lf\l"	 	\


rrdtool graph $out_proxy_tr	                        \
	 --title "Proxy transactions stats"		\
	 --vertical-label "number"     		        \
	 --alt-autoscale-max				\
	 --lower-limit 0				\
	 --base 1000					\
	 --slope-mode					\
	 --units-exponent 0				\
	 --lower-limit=0				\
							\
	 DEF:ds0=$in:nST:AVERAGE			\
	 DEF:ds1=$in:nCT:AVERAGE			\
							\
	 VDEF:ds0max=ds0,MAXIMUM			\
	 VDEF:ds0avg=ds0,AVERAGE			\
	 VDEF:ds0cur=ds0,LAST				\
	 AREA:ds0#FFC73BFF:"Total ST\: "		\
	 GPRINT:ds0cur:"Cur\: %3.0lf\t"			\
	 GPRINT:ds0avg:"Avg\: %3.0lf\t"			\
	 GPRINT:ds0max:"Max\: %3.0lf\l"	 		\
							\
	 CDEF:_ds1=ds1,-1,*				\
	 VDEF:ds1max=ds1,MAXIMUM			\
	 VDEF:ds1avg=ds1,AVERAGE			\
	 VDEF:ds1cur=ds1,LAST				\
	 AREA:_ds1#FF7D00FF:"Total CT\: "		\
	 GPRINT:ds1cur:"Cur\: %3.0lf\t"			\
	 GPRINT:ds1avg:"Avg\: %3.0lf\t"			\
	 GPRINT:ds1max:"Max\: %3.0lf\l"	 		\


rrdtool graph $out_vm                                   \
         --title "Proxy Java VM memory stats"           \
         --vertical-label "memory stats"                \
         --alt-autoscale-max                            \
         --lower-limit 0                                \
         --base 1024                                    \
         --slope-mode                                   \
							\
	 DEF:ds0=$in:vm_freememory:AVERAGE           	\
         DEF:ds1=$in:vm_maxmemory:AVERAGE            	\
         DEF:ds2=$in:vm_totalmemory:AVERAGE          	\
							\
	 VDEF:ds2max=ds2,MAXIMUM			\
	 VDEF:ds2avg=ds2,AVERAGE			\
	 VDEF:ds2cur=ds2,LAST				\
   	 AREA:ds2#00BF47:"Used memory  \t"              \
	 GPRINT:ds2cur:"Cur\: %3.2lf%S\t"		\
	 GPRINT:ds2avg:"Avg\: %3.2lf%S\t"		\
	 GPRINT:ds2max:"Max\: %3.2lf%S\l"	 	\
							\
	 VDEF:ds0max=ds0,MAXIMUM			\
	 VDEF:ds0avg=ds0,AVERAGE			\
	 VDEF:ds0cur=ds0,LAST				\
   	 AREA:ds0#00FF00:"Free memory \t"	        \
	 GPRINT:ds0cur:"Cur\: %3.2lf%S\t"		\
	 GPRINT:ds0avg:"Avg\: %3.2lf%S\t"		\
	 GPRINT:ds0max:"Max\: %3.2lf%S\l"	 	\
							\
							\
	 VDEF:ds1max=ds1,MAXIMUM			\
	 VDEF:ds1avg=ds1,AVERAGE			\
	 VDEF:ds1cur=ds1,LAST				\
	 LINE1:ds1#FF0000:"Max memory  \t"             	\
	 GPRINT:ds1cur:"Cur\: %3.2lf%S\t"		\
	 GPRINT:ds1avg:"Avg\: %3.2lf%S\t"		\
	 GPRINT:ds1max:"Max\: %3.2lf%S\l"	 	


	




